package com.yanqu.road.server.cmd.unionwar;

import com.yanqu.road.logic.cross.CrossUnionWarRankListModel;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.unionwar.UnionWarActivityServerProto;
import com.yanqu.road.pb.cross.activity.CrossActivityProto;
import com.yanqu.road.pb.rank.UnionActivityRankProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.unionwar.CrossUnionWarRankMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;


@Cmd(code = CrossProtocol.C_CROSS_UNION_WAR_GET_GUESS_REWARD, desc = "领取群英争霸竞猜奖励")
public class CrossUnionWarGetGuessRewardCmd extends CrossUnionCommand {
    private int activityId;
    private int stage;
    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionWarActivityServerProto.UnionWarGetGuessRewardMsg msg = UnionWarActivityServerProto.UnionWarGetGuessRewardMsg.parseFrom(packet.getBytes());
        activityId = msg.getActivityId();
        stage = msg.getPhase();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        UnionActivityRankProto.UnionActivityRankListMsg.Builder rankListMsg = UnionActivityRankProto.UnionActivityRankListMsg.newBuilder();
        CrossUnionWarRankListModel crossUnionWarRankListModel = CrossUnionWarRankMgr.getCrossUnionWarRankListModel(activityId, stage, groupId);
        if (crossUnionWarRankListModel != null) {
            rankListMsg = crossUnionWarRankListModel.getRankListMsg();
        }
        CrossActivityProto.UnionWarRankMsgMsg.Builder respMsg = CrossActivityProto.UnionWarRankMsgMsg.newBuilder();
        respMsg.setActivityId(activityId);
        respMsg.setPhase(stage);
        respMsg.setRankList(rankListMsg);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_UNION_WAR_GET_GUESS_REWARD_NOTIFY, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
